package xginxnote

import (
	"strings"

	"gitee.com/xiaoyutab/xgotool/optional/xnote"
	"gitee.com/xiaoyutab/xgotool/xgin"
	"gitee.com/xiaoyutab/xgotool/xstring"
	"github.com/gin-gonic/gin"
)

// 获取分页列表数据
//
//	GET	/get.menu.tree
func getMenuTree(c *gin.Context) *xgin.Response {
	type fid_struct struct {
		Ids string `json:"ids" form:"ids"` // 参数ID
	}
	temp := fid_struct{}
	if err := xgin.Bind(c, &temp); err != nil {
		return xgin.Resp().Error(err)
	}
	if temp.Ids == "" {
		return xgin.Resp().NoPage(c, []string{}, 0)
	}
	// 类型转换操作
	ids := []uint{}
	fids := strings.Split(temp.Ids, ",")
	for i := 0; i < len(fids); i++ {
		if fids[i] == "" {
			continue
		}
		ids = append(ids, xstring.ToUint(fids[i]))
	}
	tre, err := xnote.GetMenuTree(ids)
	if err != nil {
		return xgin.Resp().Error(err)
	}
	return xgin.Resp().NoPage(c, tre, len(tre))
}
